/**
 * Created by udi on 2016/11/26.
 */
var exec = require("child_process").exec;
var last;
var check = function () {
  last = exec("lsof -i:3000");
  last.on("exit", function (code) {
    if (code != '0') {
      console.error("主服务已经关闭,正在重启.");
      run();
    }
  });
  setTimeout(check, 5000);
}

var run = function () {
  last = exec("node www.js");
  last.on("exit", function (code) {
    if (code == "0") {
      console.log("主服务已重启成功.")
    }
    else {
      console.error("主服务重启失败！")
    }
  });
}
